using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Text;

namespace CodeGenTest
{
    public delegate int StandardMethod();
    public class CodeGen
    {
        private Expr expr;

        public CodeGen(Expr expr)
        {
            this.expr = expr;
        }

        public StandardMethod GetMethod()
        {
            DynamicMethod method = new DynamicMethod("Test", typeof (int), new Type[0], typeof (TestClass));
            ILGenerator ilg = method.GetILGenerator();
            expr.Eval(ilg);
            ilg.Emit(OpCodes.Ret);
            StandardMethod spMethod = (StandardMethod)method.CreateDelegate(typeof(StandardMethod));
            return spMethod;
        }
    }
}
